###################################################################################
# Replication files for: Negative References to Amicus Briefs in Judicial Reasoning
# Authors: Johan Lindholm, Daniel Naurin & Philipp Schroeder
# Published in: Journal of Law and Courts
# Contact: P.Schroeder@gsi.uni-muenchen.de

### File 2: This script provides the descriptive statistics presented in the manuscript's supplementary materials

library(tidyverse)

rm(list=ls())
homeFolder <- Sys.getenv("HOME")


# read data ---------------------------------------------------------------

load("data/mentions_issue_level.RData")
load("data/mentions_submission_level.RData")
load("data/post_nice.RData")



# descriptive statistics for table 2 of the supplementary materials -------

# continuous variables at issue level
get_descriptive_continuous <- function(var){
  out <- mentions_issue_level |>
    summarize(mean(var, na.rm = TRUE),
              sd(var, na.rm = TRUE),
              min(var, na.rm = TRUE),
              max(var, na.rm = TRUE))
  return(out)
}

get_descriptive_continuous(mentions_issue_level$subject_matter_category.count) # complexity
get_descriptive_continuous(mentions_issue_level$ms_pos_auto0) # MS favouring no restrictions
get_descriptive_continuous(mentions_issue_level$ms_pos_auto1) # MS favouring restrictions
get_descriptive_continuous(mentions_issue_level$net_ms_autonomy) # MS favouring restrictions
get_descriptive_continuous(mentions_issue_level$sources_case_law.ag) # sources case law
get_descriptive_continuous(mentions_issue_level$sources_primary.ag) # sources primary law
get_descriptive_continuous(mentions_issue_level$sources_secondary.ag) # sources secondary law
get_descriptive_continuous(mentions_issue_level$duration_since_ag) # duration
get_descriptive_continuous(mentions_issue_level$panel_size) # panel size
get_descriptive_continuous(mentions_issue_level$mentioned_negative) # count negative mentions
get_descriptive_continuous(mentions_issue_level$mentioned_positive) # count negative mentions
get_descriptive_continuous(mentions_issue_level$mentioned_neutral) # count negative mentions



# descriptive statistics for table 3 of the supplementary materials -------

table(mentions_issue_level$com_pos_auto.factor)
table(mentions_issue_level$ag_pos_auto.factor)
table(mentions_issue_level$cjeu_pos_auto.factor)
table(mentions_issue_level$ag_com_disagreement)
table(mentions_issue_level$ag_cjeu_disagreement)
table(post_nice$ag_opinion_submitted)
table(mentions_issue_level$mentioned_negative_dummy)
table(mentions_issue_level$mentioned_positive_dummy)
table(mentions_issue_level$mentioned_neutral_dummy)



# descriptive statistics for table 4 of the supplementary materials -------

submission_subset <- mentions_submission_level |>
  filter(actor_type == "ms")

get_descriptive_continuous <- function(var){
  out <- submission_subset |>
    summarize(mean(var, na.rm = TRUE),
              sd(var, na.rm = TRUE),
              min(var, na.rm = TRUE),
              max(var, na.rm = TRUE))
  return(out)
}

get_descriptive_continuous(submission_subset$subject_matter_category.count) # complexity
get_descriptive_continuous(submission_subset$panel_size) # panel size
get_descriptive_continuous(submission_subset$mentioned_negative) # negative mentions counts
get_descriptive_continuous(submission_subset$mentioned_positive) # positive mentions counts
get_descriptive_continuous(submission_subset$mentioned_neutral) # neutral mentions counts



# descriptive statistics for table 5 of the supplementary materials -------

table(submission_subset$pos_auto.factor)
table(submission_subset$com_pos_auto.factor)
table(submission_subset$ag_pos_auto.factor)
table(submission_subset$cjeu_pos_auto.factor)
table(submission_subset$observation_referring_ms)
table(submission_subset$oral_observation)
table(submission_subset$largest_ms)
submission_subset$mentioned_negative_dummy <- ifelse(submission_subset$mentioned_negative > 0, 1, 0)
table(submission_subset$mentioned_negative_dummy)
submission_subset$mentioned_positive_dummy <- ifelse(submission_subset$mentioned_positive > 0, 1, 0)
table(submission_subset$mentioned_positive_dummy)
submission_subset$mentioned_neutral_dummy <- ifelse(submission_subset$mentioned_neutral > 0, 1, 0)
table(submission_subset$mentioned_neutral_dummy)

